import string
import win32con
import re

def _notnum(n):
    return False if re.match("^[-+]?[0-9]+$", n) else True 

def _parse(m):
    try:
        return win32con.__dict__[m]
    except Exception, e:
        import sys
        print >> sys.stderr, "win32con property '%s' not found" % m
        return 0

def hotkey(val):
    a = string.split(val)
    if len(a) == 0:
        return None
    #if we only have an id, but no modifier
    if len(a) == 1:
        a.append(0)
    else: 
        #we have a modifier
        if _notnum(a[1]):
            #check to see if we have multiple modifiers
            modArray = string.split(a[1], "|")
            mods = 0
            for str in modArray:
                mods |= int(_parse(str)) 
            a[1] = mods
        else:
            a[1] = int(a[1])
    if _notnum(a[0]): #ensure id type
        a[0] = _parse(a[0])
    else:
        a[0] = int(a[0])
    a.append(False)
    return a